package com.alibaba.citrus.ots.application.report.ability.repository.impl;

import com.alibaba.citrus.ots.application.report.ability.repository.OrderProgressMonitorReportWriteReporitory;
import com.epoch.app.otsapplicationreportsdk.model.dto.OrderProgressMonitorReportSDO;
import com.epoch.app.otsapplicationreportsdk.orderprogressmonitorreport.dto.UpdateResponse;
import com.epoch.app.otsapplicationreportsdk.orderprogressmonitorreport.model.OrderProgressMonitorReport;
import com.epoch.app.otsapplicationreportsdk.orderprogressmonitorreport.service.OrderProgressMonitorReportService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author zhoubc
 * @description: TODO
 * @date 2021/12/31 17:51
 */
@Component
public class OrderProgressMonitorReportWriteReporitoryImpl implements OrderProgressMonitorReportWriteReporitory {

    @Resource
    OrderProgressMonitorReportService orderProgressMonitorReportService;

    @Override
    public String add(OrderProgressMonitorReportSDO sdo) {
        OrderProgressMonitorReport orderProgressMonitorReport = new OrderProgressMonitorReport();
        BeanUtils.copyProperties(sdo,orderProgressMonitorReport);
        Map m = (Map)orderProgressMonitorReportService.create(orderProgressMonitorReport);
        Map result = (Map)m.get("result");
        return (String)result.get("lastInsertId");
    }

    @Override
    public Integer update(OrderProgressMonitorReportSDO sdo) {
        OrderProgressMonitorReport orderProgressMonitorReport = new OrderProgressMonitorReport();
        BeanUtils.copyProperties(sdo,orderProgressMonitorReport);
        UpdateResponse response = orderProgressMonitorReportService.update(orderProgressMonitorReport);
        return response.getCount();
    }
}
